package com.xbongbong.paas.enums;




import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import com.xbongbong.saas.enums.subform.ContractProductSubFormEnum;
import lombok.Getter;

/**
 * BI产品相关的枚举（可能不包含所有）
 * 包含其他
 *
 * @author 梁鲁江
 */
@Getter
public enum BIProductEnum {
    /**
     *保证formId的唯一性
     */
    //合同 type = 201
    CONTRACT_PRODUCT(XbbRefTypeEnum.CONTRACT_PRODUCT.getCode(),XbbRefTypeEnum.CONTRACT.getCode(), XbbRefTypeEnum.CONTRACT_PRODUCT.getAlias(), "enum.bIProduct.name.contract_product", ContractProductSubFormEnum.CONTRACT_ID.getDataAttr()),
    SALES_OPPORTUNITY_PRODUCT(XbbRefTypeEnum.SALES_OPPORTUNITY_PRODUCT.getCode(),XbbRefTypeEnum.SALES_OPPORTUNITY.getCode(), XbbRefTypeEnum.SALES_OPPORTUNITY_PRODUCT.getAlias(), "enum.bIProduct.name.sales_opportunity_product","num_13"),
    //todo 等海滨补corpid
/*
    INSTOCK_PRODUCT(XbbRefTypeEnum.INSTOCK_PRODUCT.getCode(),XbbRefTypeEnum.INSTOCK.getCode(), XbbRefTypeEnum.INSTOCK_PRODUCT.getAlias(), "enum.bIProduct.name.instock_product","num_13"),
    OUTSTOCK_PRODUCT(XbbRefTypeEnum.OUTSTOCK_PRODUCT.getCode(),XbbRefTypeEnum.OUTSTOCK.getCode(), XbbRefTypeEnum.OUTSTOCK_PRODUCT.getAlias(),"enum.bIProduct.name.outstock_product","num_13"),
*/

    //报价单
    QUOTATION_PRODUCT(XbbRefTypeEnum.QUOTATION_PRODUCT.getCode(),XbbRefTypeEnum.QUOTATION.getCode(), XbbRefTypeEnum.QUOTATION_PRODUCT.getAlias(), "enum.bIProduct.name.quotation_product","num_13"),
    //bom单
    PRODUCTION_ORDER_PRODUCT(XbbRefTypeEnum.PRODUCTION_ORDER_PRODUCT.getCode(),XbbRefTypeEnum.PRODUCTION_ORDER.getCode(), XbbRefTypeEnum.PRODUCTION_ORDER_PRODUCT.getAlias(), "enum.bIProduct.name.production_order_product","num_13"),
    SUPPLIER_PRODUCT(XbbRefTypeEnum.SUPPLIER_PRODUCT.getCode(),XbbRefTypeEnum.SUPPLIER.getCode(), XbbRefTypeEnum.SUPPLIER_PRODUCT.getAlias(), "enum.bIProduct.name.supplier_product","num_13"),
    PURCHASE_PRODUCT(XbbRefTypeEnum.PURCHASE_PRODUCT.getCode(),XbbRefTypeEnum.PURCHASE.getCode(), XbbRefTypeEnum.PURCHASE_PRODUCT.getAlias(), "enum.bIProduct.name.purchase_product","num_13"),
    RETURNED_PURCHASE_PRODUCT(XbbRefTypeEnum.RETURNEDPURCHASE_PRODUCT.getCode(),XbbRefTypeEnum.RETURNED_PURCHASE.getCode(), XbbRefTypeEnum.RETURNEDPURCHASE_PRODUCT.getAlias(), "enum.bIProduct.name.returned_purchase_product","num_13"),
    //装配单 盘点单 调拨单
    ASSEMBLE_PRODUCT(XbbRefTypeEnum.ASSEMBLE_PRODUCT.getCode(),XbbRefTypeEnum.ASSEMBLE.getCode(), XbbRefTypeEnum.ASSEMBLE_PRODUCT.getAlias(), "enum.bIProduct.name.assemble_product","num_13"),
    ASSEMBLE_INPRODUCTS(XbbRefTypeEnum.ASSEMBLE_INPRODUCTS.getCode(),XbbRefTypeEnum.ASSEMBLE.getCode(), XbbRefTypeEnum.ASSEMBLE_INPRODUCTS.getAlias(), "enum.bIProduct.name.assemble_in_products","num_13"),
    INVENTORY_PRODUCT(XbbRefTypeEnum.INVENTORY_PRODUCT.getCode(),XbbRefTypeEnum.INVENTORY.getCode(), XbbRefTypeEnum.INVENTORY_PRODUCT.getAlias(), "enum.bIProduct.name.inventory_product","num_13"),
    TRANSFER_PRODUCT(XbbRefTypeEnum.TRANSFER_PRODUCT.getCode(),XbbRefTypeEnum.TRANSFER.getCode(), XbbRefTypeEnum.TRANSFER_PRODUCT.getAlias(), "enum.bIProduct.name.transfer_product","num_13"),


    ;

    /**
     * 枚举值 --
     */
    private final Integer code;
    /**
     * 父文档的枚举值
     */
    private final Integer parentCode;
    /**
     * 枚举描述 --英文名称
     */
    private final String alias;
    /**
     * 显示名称
     */
    private final String name;
    /**
     * 关联字段
     */
    private final String linkAttr;

    /**
     * 构造一个<code>XbbRefTypeEnum</code>枚举对象
     *
     * @param code  枚举Code
     * @param alias 枚举别名
     */
    BIProductEnum(Integer code, Integer parentCode, String alias,String name,String linkAttr) {
        this.code = code;
        this.parentCode = parentCode;
        this.alias = alias;
        this.name = name;
        this.linkAttr = linkAttr;
    }

    /**
     * 通过枚举 alias 获得枚举
     *
     * @param alias 枚举别名
     *
     * @return BIProductEnum
     */
    public static BIProductEnum getByAlias(String alias) {
        for (BIProductEnum cacheCode : values()) {
            if (cacheCode.getAlias().equals(alias)) {
                return cacheCode;
            }
        }
        return null;
    }

    /**
     * 通过枚举 code 获得枚举
     *
     * @param code 枚举Code
     *
     * @return BIProductEnum
     */
    public static BIProductEnum getByCode(Integer code) {
        for (BIProductEnum cacheCode : values()) {
            if (Objects.equals(code,cacheCode.getCode())) {
                return cacheCode;
            }
        }
        return null;
    }

    /**
     * 获取全部枚举
     *
     * @return List<XbbRefTypeEnum>
     */
    public static List<BIProductEnum> getAllEnum() {
        List<BIProductEnum> list = new ArrayList<>();
        for (BIProductEnum cache : values()) {
            if (cache == null) {
                continue;
            }
            list.add(cache);
        }
        return list;
    }

    /**
     * 获取全部枚举值
     *
     * @return List<String>
     */
    public List<String> getAllEnumAlis() {
        List<String> list = new ArrayList<>();
        for (BIProductEnum cache : values()) {
            if (cache == null) {
                continue;
            }
            list.add(cache.getAlias());
        }
        return list;
    }

    /**
     * 获取所有code值
     * @return
     */
    public static List<Integer> getAllEnumCode() {
        List<Integer> list = new ArrayList<>();
        for (BIProductEnum cache : values()) {
            if (cache == null) {
                continue;
            }
            list.add(cache.getCode());
        }
        return list;
    }

    /**
     * 根据parentCode获取枚举
     * @param parentCode
     * @return
     */
    public static BIProductEnum getByParentCode(Integer parentCode) {
        for (BIProductEnum cacheCode : values()) {
            if (cacheCode.getParentCode().equals(parentCode)) {
                return cacheCode;
            }
        }
        return null;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
